package com.tengju.user.domain.model.user;

import com.tengju.user.domain.model.sign.StarAccountTypeEnum;
import lombok.Getter;

import java.util.Arrays;

@Getter
public enum StarRoleEnum {
    NONE(0,"没有星级"),
    SERVICE_PROVIDER(100, "服务商"),
    OPERATOR(200, "运营商");

    private Integer code;
    private String desc;

    StarRoleEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static StarRoleEnum parseByRole(Integer starRole) {
        return Arrays.stream(StarRoleEnum.values())
                .filter(k -> k.getCode().equals(starRole))
                .findFirst().orElse(null);
    }

    public boolean isMatchAccountType(Integer accountType) {
        if (accountType == null) {
            return false;
        }
        StarAccountTypeEnum starAccountTypeEnum = StarAccountTypeEnum.getByType(accountType);
        if (this.equals(NONE)) {
            return false;
        } else if (this.equals(SERVICE_PROVIDER)) {
            return starAccountTypeEnum != null;
        } else if (this.equals(OPERATOR)) {
            return starAccountTypeEnum != null;
        } else {
            return false;
        }
    }

    public static boolean isServiceProvider(Integer starRole) {
        StarRoleEnum starRoleEnum = parseByRole(starRole);
        return SERVICE_PROVIDER.equals(starRoleEnum);
    }

    public static boolean isOperator(Integer starRole) {
        StarRoleEnum starRoleEnum = parseByRole(starRole);
        return OPERATOR.equals(starRoleEnum);
    }


}
